package com.example.duomeitijuhe.ui;
import android.accounts.Account;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.duomeitijuhe.R;
import com.example.duomeitijuhe.db.OperateDatabase;
import com.example.duomeitijuhe.db.UserDatabaseHelper;
import com.example.duomeitijuhe.others.ActivityCollector;

/**
 * Created by Michael on 2014/10/13.
 */
public class RegisterActivity extends Activity implements View.OnClickListener{

    EditText accountEdit;
    EditText passwordEdit;
    EditText confirmPasswordEdit;
    EditText judgeRegisterEdit;
    Button registerButton;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.register);
        ActivityCollector.addActivity(this);
        initData();


        registerButton.setOnClickListener(this);
    }
    public void initData(){
        accountEdit = (EditText)findViewById(R.id.register_account_edit);
        passwordEdit = (EditText)findViewById(R.id.register_password_edit);
        confirmPasswordEdit = (EditText)findViewById(R.id.register_password_confirm_edit);
        judgeRegisterEdit = (EditText)findViewById(R.id.judge_register_edit);
        registerButton = (Button)findViewById(R.id.r_register_button);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.r_register_button:
                String accountStr = accountEdit.getText().toString();
                if (!accountStr.equals("")){
                    String passwordStr = passwordEdit.getText().toString();
                    if (!passwordStr.equals("")){
                        String confirmPasswordStr = confirmPasswordEdit.getText().toString();
                        if (!confirmPasswordStr.equals("")){
                            if (passwordStr.equals(confirmPasswordStr)){

                                OperateDatabase operateDatabase = new OperateDatabase(RegisterActivity.this,1);
                                operateDatabase.insertDbAccount(accountStr,passwordStr);
                                judgeRegisterEdit.setText("注册成功");
                                Intent intent = new Intent(RegisterActivity.this,PlatformBindActivity.class);
                                startActivity(intent);
                            }else {
                                judgeRegisterEdit.setText("注册失败，两次密码不同");
                            }
                        }
                    }
                }else {
                    Toast.makeText(RegisterActivity.this,"账号为空，请输入账号",Toast.LENGTH_SHORT).show();
                }
                break;

            default:
                break;
        }
    }
}